{include file="public/layout" /}

<body style="background-color: rgb(255, 255, 255); overflow: auto; cursor: default; -moz-user-select: inherit;">
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<div class="page">
    {include file="field/bar" /}
    <div class="flexigrid">
        <div class="mDiv">
            <div class="ftitle">
                <h3>
                    <select id="select_channel" style="height: 26px;">
                        {volist name="$channeltype_list" id="vo"}
                        <option value="{$vo.id}" {eq name="$Request.param.channel_id" value="$vo.id"}selected{/eq}>{$vo.title}</option>
                        {/volist}
                    </select>&nbsp;字段列表
                </h3>
                <h5>(共{$pager->totalRows}条记录)</h5>
            </div>
            <div title="刷新数据" class="pReload"><i class="fa fa-refresh"></i></div>
            <form class="navbar-form form-inline" action="{:U('Field/channel_index')}" method="get" onsubmit="layer_loading('正在处理');">
                <div class="sDiv">
                    <div class="sDiv2">
                        <input type="hidden" name="searchopt" value="1">
                        <input type="hidden" name="channel_id" id="channel_id" value="{$channel_id|default='1'}">
                        <input type="text" size="30" name="keywords" value="{$Request.param.keywords}" class="qsbox" placeholder="字段搜索...">
                        <input type="submit" class="btn" value="搜索">
                    </div>
                    <div class="sDiv2">
                        <input type="button" class="btn" value="重置" onClick="window.location.href='{:U('Field/channel_index', array("channel_id"=>$channel_id))}';">
                    </div>
                </div>
            </form>
        </div>
        <div class="hDiv">
            <div class="hDivBox">
                <table cellspacing="0" cellpadding="0" style="width: 100%">
                    <thead>
                    <tr>
                        <th abbr="article_title" axis="col3" class="w50">
                            <div class="tc">ID</div>
                        </th>
                        <th abbr="article_title" axis="col3" class="">
                            <div class="">字段标题</div>
                        </th>
                        <th abbr="article_time" axis="col6" class="w160">
                            <div class="tc">字段名称</div>
                        </th>
                        <th abbr="article_time" axis="col6" class="w120">
                            <div class="tc">字段类型</div>
                        </th>
                        <th abbr="article_time" axis="col6" class="w70">
                            <div class="tc">字段分类</div>
                        </th>
                        <th abbr="article_time" axis="col6" class="w100">
                            <div class="tc">更新时间</div>
                        </th>
                        <th axis="col1" class="w180">
                            <div class="tc">操作</div>
                        </th>
                        <th abbr="article_time" axis="col6" class="w60">
                            <div class="tc">排序</div>
                        </th>
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
        <div class="bDiv" style="height: auto;">
            <div id="flexigrid" cellpadding="0" cellspacing="0" border="0">
                <table style="width: 100%;">
                    <tbody>
                    {empty name="list"}
                        <tr>
                            <td class="no-data" align="center" axis="col0" colspan="50">
                                <i class="fa fa-exclamation-circle"></i>没有符合条件的记录
                            </td>
                        </tr>
                    {else/}
                        {foreach name="list" item="vo" key="k" }
                        <tr>
                            <td class="sort">
                                <div class="tc w50">
                                    {$vo.id}
                                </div>
                            </td>
                            <td style="width: 100%">
                                <div style="">
                                {if condition="($vo['ifsystem'] eq 1) OR (1 eq $vo['ifmain'])"}
                                    {$vo.title}
                                {else /}
                                    {eq name="'Field@channel_edit'|is_check_access" value="1"}
                                    <a href="{:U('Field/channel_edit',array('channel_id'=>$channel_id,'id'=>$vo['id']))}">{$vo.title}</a>
                                    {else /}
                                    {$vo.title}
                                    {/eq}
                                {/if}
                                </div>
                            </td>
                            <td class="">
                                <div class="w160 tc">
                                    {$vo.name}
                                </div>
                            </td>
                            <td class="">
                                <div class="w120 tc">
                                    {$fieldtypeList[$vo['dtype']]['title']|default='数据错误'}
                                </div>
                            </td>
                            <td>
                                <div class="tc w70">
                                    {if condition="($vo['ifsystem'] eq 1) OR (1 eq $vo['ifmain'])"}
                                        系统
                                    {else /}
                                        自定义
                                    {/if}
                                </div>
                            </td>
                            <td>
                                <div class="w100 tc">
                                    {$vo.update_time|date='Y-m-d',###}
                                </div>
                            </td>
                            <td class="">
                                <div class="w180 tc">
                                {if condition="($vo['ifsystem'] eq 1) OR (1 eq $vo['ifmain'])"}
                                    ——————
                                {else /}
                                    {eq name="'Field@channel_edit'|is_check_access" value="1"}
                                    <a href="{:U('Field/channel_edit',array('channel_id'=>$channel_id,'id'=>$vo['id']))}" class="btn blue"><i class="fa fa-pencil-square-o"></i>编辑</a>
                                    {/eq}
                                    {eq name="'Field@channel_del'|is_check_access" value="1"}
                                    <a class="btn red"  href="javascript:void(0);" data-url="{:U('Field/channel_del', array('channel_id'=>$channel_id))}" data-id="{$vo.id}" onClick="delfun(this);"><i class="fa fa-trash-o"></i>删除</a>
                                    {/eq}
                                {/if}
                                <a class="btn blue" href="javascript:void(0);" onclick="copyToClipBoard('{$vo['name']}', {$channel_id|default='0'})">标签调用</a>
                                </div>
                            </td>
                            <td class="sort">
                                <div class="w60 tc">
                                {if condition="($vo['ifsystem'] eq 1) OR (1 eq $vo['ifmain'])"}
                                    ————
                                {else /}
                                    {eq name="'Field@channel_edit'|is_check_access" value="1"}
                                    <input style="text-align: left;" type="text" onkeyup="this.value=this.value.replace(/[^\d]/g,'');" onpaste="this.value=this.value.replace(/[^\d]/g,'')" onchange="changeTableVal('channelfield','id','{$vo.id}','sort_order',this);"  size="4"  value="{$vo.sort_order}" />
                                    {else /}
                                    {$vo.sort_order}
                                    {/eq}
                                {/if}
                                </div>
                            </td>
                            
                        </tr>
                        {/foreach}
                    {/empty}
                    </tbody>
                </table>
            </div>
            <div class="iDiv" style="display: none;"></div>
        </div>
        <div class="tDiv">
            <div class="tDiv2">
                {eq name="'Field@channel_add'|is_check_access" value="1"}
                <div class="fbutton">
                    <a href="{:U('Field/channel_add', array('channel_id'=>$channel_id))}">
                        <div class="add" title="新增字段">
                            <span class="red"><i class="fa fa-plus"></i>新增字段</span>
                        </div>
                    </a>
                </div>
                {/eq}
            </div>
            <div style="clear:both"></div>
        </div>
        <!--分页位置-->
        {$page}
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function(){

        // 表格行点击选中切换
        $('#flexigrid > table>tbody >tr').click(function(){
            $(this).toggleClass('trSelected');
        });

        // 点击刷新数据
        $('.fa-refresh').click(function(){
            location.href = location.href;
        });

        /*模型下拉框跳转*/
        $('#select_channel').change(function(){
            var channel_id = $(this).val();
            var url = "{:U('Field/channel_index')}";
            if (url.indexOf('?') > -1) {
                url += '&';
            } else {
                url += '?';
            }
            url += 'channel_id='+channel_id;
            layer_loading('正在处理');
            window.location.href = url;
        });
        /*--end*/
    });

    function delfun(obj){
      var title = $(obj).attr('data-typename');
      layer.confirm('<font color="#ff0000">数据将无法恢复</font>，确认删除？', {
          title: title,
          btn: ['确定','取消'] //按钮
        }, function(){
          layer_loading('正在处理');
        // 确定
          $.ajax({
            type : 'post',
            url : $(obj).attr('data-url'),
            data : {del_id:$(obj).attr('data-id')},
            dataType : 'json',
            success : function(data){
              layer.closeAll();
              if(data.status == 1){
                layer.msg(data.msg, {icon: 1});
                window.location.reload();
                // $('tr[data-id="'+$(obj).attr('data-id')+'"]').remove();
              }else{
                layer.alert(data.msg, {icon: 2});  //alert(data);
              }
            }
          })
        }, function(index){
          layer.close(index);
        }
      );
      return false;
    }  

    /**
     * 标签调用js
     * @param string  fieldname 字段名称
     * @param intval  channel_id 模型ID
     */
    function copyToClipBoard(fieldname, channel_id) {
        if (6 == channel_id) {
            var liststr = "{eyou:type typeid='栏目ID' addfields='"+fieldname+"'}\r\n    {$"+"field."+fieldname+"}\r\n{/eyou:type";
            var contentdiv = '<div class="dialog_content" style="margin: 0px; padding: 0px;"><dl style="padding:10px 30px;line-height:30px;"><dd>列表/内容页：</dd>'
            contentdiv += '<dd><input type="text" style=" width:400px;margin-bottom:10px;" value="{$'+'eyou.field.'+fieldname+'}"></dd>'
            contentdiv += '<dd>标签 type 属性 addfields 调用：</dd>'
            contentdiv += '<dd><textarea rows="4" cols="60" style="width:400px;height:60px;">' + liststr + '}</textarea></dd>'

        } else {
            var liststr = "{eyou:arcview id='eyoav' addfields='"+fieldname+"'}\r\n    {$"+"eyoav."+fieldname+"}\r\n{/eyou:arcview";
            var contentdiv = '<div class="dialog_content" style="margin: 0px; padding: 0px;"><dl style="padding:10px 30px;line-height:30px;"><dd>内容页：</dd>'
            contentdiv += '<dd><input type="text" style=" width:400px;margin-bottom:10px;" value="{$'+'eyou.field.'+fieldname+'}"></dd>'
            contentdiv += '<dd>标签 arclist / list 内调用：</dd>'
            contentdiv += '<dd><textarea rows="4" cols="60" style="width:400px;height:60px;">' + liststr + '}</textarea></dd>'
        }
        contentdiv += '<dd style="border-top: dotted 1px #E7E7E7; color: #F60;">请将相应标签复制并粘贴到对应模板文件中！</dd></dl></div>'
        layer.open({
            title: '标签调用',
            type: 1,
            skin: 'layui-layer-demo',
            area: ['480px', '280px'], //宽高
            content: contentdiv
        });
    }
</script>

{include file="public/footer" /}